const connection = require('../app/database')

class LabelService {
    // 1.创建标签
    async create(name) {
        try {
            const statement = `INSERT INTO label (name) VALUES (?);`
            const [result] = await connection.execute(statement, [name])
            return result
        } catch (error) {
            console.log(error);
        }
    }

    // 查询标签是否存在
    async getLabelByName(name) {
        try {
            const statement = `SELECT * FROM label WHERE name=?;`
            const [result] = await connection.execute(statement, [name])
            return result[0]
        } catch (error) {
            console.log(error);
        }
    }

    // 获取标签
    async getLabels(limit, offset) {
        try {
            const statement = `SELECT * FROM label LIMIT ?,?;`
            const [result] = await connection.execute(statement, [offset, limit])
            return result
        } catch (error) {
            console.log(error);
        }
    }
}

module.exports = new LabelService()